

#include "kemr.h"
#include <iostream>
#include "solid.h"
#include "hedmodel.h"
#include "face.h"
#include "loop.h"
#include "point.h"
#include "vertex.h"
#include "halfedge.h"


KEMR::KEMR(HalfEdge* _h1, HalfEdge* _h2)
: h1( _h1 )
, h2( _h2 )
{

}




void
KEMR::execute()
{
  std::cout << "\nKEMR::execute() \n";

  register HalfEdge *h3,*h4;
  Loop* ol= h1->getLoop();
  Loop* nl = new Loop(ol->getFace());
  Edge* killedge = h1->getEdg();
  h3 = h1->getNxt();
  h1->setNxt(h2->getNxt());
  h2->getNxt()->setPrv(h1);
  h2->setNxt(h3);
  h3->setPrv(h2);
  h4 = h2;
  do
  {
    h4->setWloop(nl);
  }
  while((h4 = h4->getNxt()) != h2);

  ol->setLedg(h3 = h1->delhe());
  nl->setLedg(h4 = h2->delhe());

  h3->getVtx()->setVedge( (h3->getEdg()) ? h3 : NULL );
  h4->getVtx()->setVedge( (h4->getEdg()) ? h4 : NULL );
  h3->getNxt()->getVtx()->setVedge( (h3->getNxt()->getEdg()) ? h3->getNxt() : NULL );
  h4->getNxt()->getVtx()->setVedge( (h4->getNxt()->getEdg()) ? h4->getNxt() : NULL );

  delete killedge;

}


void
KEMR::unExecute()
{
  std::cout << "\nKEMR::unExecute() NOT IMPLEMENTED!\n";
}
